<?php


require_once( SITEBASE."/system/db/dbconnect.class.php" );
//include "db/dbconnect.class.php";
class DbCategory extends Connection
{	

function selectCategory($categoryId){
		$sql = "SELECT * FROM `categories` WHERE `id` = ".$categoryId.";";
 		$result = $this->selectQuery($sql);
		return $result;
}
	
	
	function addCategory( $categoryName, $subCatName, $sectorId, $group){
	
		if ($subCatName == "") {
		
			$subcat = NULL;
		
		} else {
		
			$subcat = $subCatName;
		
		}
	
		$sql = "INSERT INTO `categories` VALUES ('', '".$sectorId."',  '".$categoryName."', '".$subcat."');";
 		$result = $this->selectQuery($sql);
 		
 		if ($group == true){
 		$sql = "INSERT INTO `categories_group` VALUES ('', '".$categoryName."', '".$sectorId."', LAST_INSERT_ID());";
 		$result = $this->selectQuery($sql);
 		}
 		if ($result){
 		header("Location:index.php?act=promos&sector=".$sectorId."");
 		}
	}
	
	


 
	

	
	function updateCategory( $categoryName, $sectorId, $id){
	
		$sql = "UPDATE `categories` SET `nameOfCategory` = '".$categoryName."' WHERE `categories`.`id` = ".$id." LIMIT 1 ;";
 		$result = $this->selectQuery($sql);
 		
 		if ($result){
 		// index.php?act=displaycurrentcategories&sector=1
 		header("Location:index.php?act=displaycurrentcategories&sector=".$sectorId."");
 		}
	}
	
	function deleteCategory( $id , $sectorId){
	
		$sql = "DELETE FROM `categories` WHERE `id` = ".$id.";";
 		$result = $this->selectQuery($sql);
 		
 		$sql = "DELETE FROM `categories_group` WHERE `category_id` = ".$id.";";
 		$result = $this->selectQuery($sql);
 		
 		if ($result){
 		header("Location:index.php?act=displaycurrentcategories&sector=".$sectorId."");
 		}
	}
}
	
?>